import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_types.dart';
import 'package:xindong/models/user/xindong_base_user.dart';
import 'package:xindong/models/user/xindong_home_user.dart';
import 'package:xindong/models/user/xindong_user.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';

class XinDongBiaoQianList extends StatelessWidget {
  final XinDongBaseUser user;

  const XinDongBiaoQianList({Key? key, required this.user}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> tagList = [];
    tagList.add(sexAgeTag(isMale: user.isMale, age: user.age));
    // if ("${user.is_identity_authentication}" == "1") {
    //   tagList.add(AssetsRes.BIAOQIAN_TXRZ);
    // }
    // if (user.is_vip == 1) {
    //   tagList.add(AssetsRes.BIAOQIAN_IMMORTAL);
    // }

    if (user.img_auth == 1) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_FACE_CERTIFICATE));
    }
    if (user.isShiMing) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_REALNAME, fit: BoxFit.fitHeight));
    }
    if (user.realname_auth == 2) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_FACE_CERTIFICATE, fit: BoxFit.fitHeight));
    }
    if (user.is_crown == 1) {
      tagList.add(
        ImageUtil.networkImageUrl(user.crown?.icon, width: 20, fit: BoxFit.fitHeight),
      );
    }

    if (tagList.isEmpty) {
      return const SizedBox();
    }
    return Flexible(
      child: SizedBox(
        height: 16,
        // width: 38.0 * tagList.length + 5 * (tagList.length),
        child: ListView.separated(
          // shrinkWrap: true,
          // physics: const NeverScrollableScrollPhysics(),
          scrollDirection: Axis.horizontal,
          itemCount: tagList.length,
          itemBuilder: (BuildContext context, int index) => tagList[index],
          separatorBuilder: (BuildContext context, int index) => const SizedBox(width: 5),
        ),
      ),
    );
  }
}

class XinDongLabelsHomeList extends StatelessWidget {
  final XinDongHomeUser user;

  const XinDongLabelsHomeList({Key? key, required this.user}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> tagList = [];
    tagList.add(sexAgeTag(isMale: user.user_sex == Gender.male, age: user.user_age));
    // if ("${user.is_identity_authentication}" == "1") {
    //   tagList.add(AssetsRes.BIAOQIAN_TXRZ);
    // }
    // if (user.is_vip == 1) {
    //   tagList.add(AssetsRes.BIAOQIAN_IMMORTAL);
    // }

    if (user.img_auth == 1) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_FACE_CERTIFICATE));
    }
    if (user.isShiMing) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_REALNAME, fit: BoxFit.fitHeight));
    }
    if (user.realname_auth == 2) {
      tagList.add(ImageUtil.asset(AssetsRes.LABEL_FACE_CERTIFICATE, fit: BoxFit.fitHeight));
    }
    if (!TextUtil.isEmpty(user.is_topup)) {
      tagList.add(
        ImageUtil.networkImageUrl(user.is_topup, width: 20, fit: BoxFit.fitHeight),
      );
    }
    if (user.is_crown == 1) {
      tagList.add(
        ImageUtil.networkImageUrl(user.crown?.icon, width: 20, fit: BoxFit.fitHeight),
      );
    }
    if (tagList.isEmpty) {
      return const SizedBox();
    }
    return Flexible(
      fit: FlexFit.tight,
      child: SizedBox(
        height: 16,
        child: ListView.separated(
          scrollDirection: Axis.horizontal,
          itemCount: tagList.length,
          itemBuilder: (BuildContext context, int index) => tagList[index],
          separatorBuilder: (BuildContext context, int index) => const SizedBox(width: 5),
        ),
      ),
    );
  }
}

Widget sexAgeTag({required bool isMale, required dynamic age}) {
  Color color = DZColors.hexStringColor(isMale ? "#5BAAEB" : "#EB558A");
  return Stack(
    alignment: Alignment.center,
    children: [
      ImageUtil.asset(
        isMale ? AssetsRes.LABEL_SEX_MAN : AssetsRes.LABEL_SEX_WOMAN,
        fit: BoxFit.fitHeight,
      ),
      Positioned(
        left: 18,
        child: Text(
          "$age",
          style: TextStyle(color: color, fontSize: 11, height: 1.2),
        ),
      )
    ],
  );
}
